package cn.xfdzx.android.apps.shop.adapter;

import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.activity.XFDGoodsDeatailsActivity;
import cn.xfdzx.android.apps.shop.activity.XFDGoodsLimitActivity;
import cn.xfdzx.android.apps.shop.bean.GoodsLimitBean;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

/**
 * Creator: zf.
 * Date: 2020/8/30.
 * Description:限购商品列表适配器-首页活动适配器.
 */
public class GoodsLimitList_HomePageAdapter extends BaseQuickAdapter<GoodsLimitBean.DataBean, BaseViewHolder> {
    //private AfterServiceGoodsListAdapter.OnItemOnClickListener onItemOnClickListener;
    private List<GoodsLimitBean.DataBean> dataBeans = new ArrayList<>();//商品列表

    public GoodsLimitList_HomePageAdapter(@Nullable List<GoodsLimitBean.DataBean> data) {
        super(R.layout.item_firstlimit, data);
        this.dataBeans = data;
    }

    @Override
    public void setData(int index, @NonNull GoodsLimitBean.DataBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final GoodsLimitBean.DataBean date) {
        TextView tv_oldprice = viewHolder.getView(R.id.tv_oldprice);
        //ImageView imageView = viewHolder.getView(R.id.img_goods);
        CornerImageView imageView = viewHolder.getView(R.id.img_goods);
        imageView.setType(CornerImageView.TYPE_ROUND);

        viewHolder.setText(R.id.tv_oldprice,"¥"+date.getOriginal_price())
                .setText(R.id.tv_price,"¥"+date.getConcessional_price());
        tv_oldprice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG); //中划线
        ImageGlideUtil.loadImage(mContext,imageView,date.getImage());

        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, XFDGoodsLimitActivity.class);
                intent.putExtra("good_id",date.getGood_id()+"");
                mContext.startActivity(intent);
            }
        });
    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<GoodsLimitBean.DataBean> list){
        this.dataBeans = list;
        super.replaceData(list);
    }

    public void addDatas(List<GoodsLimitBean.DataBean>  list){
        super.addData(list);
        //mData.addAll(list);
    }

    private GoodsLimitList_HomePageAdapter.OnItemOnClickListener onItemOnClickListener;
    public void setOnListItemGoBuyListener(GoodsLimitList_HomePageAdapter.OnItemOnClickListener onItemGoBuy) {
        this.onItemOnClickListener = onItemGoBuy;
    }

    public interface OnItemOnClickListener {
        void onItemBuyClick(String goodsId);
    }


}
